package com.leyou.item.dto;

import com.leyou.common.dto.BaseDTO;
import com.leyou.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class SpecParamDTO extends BaseDTO {
    private Long id;
    private Long categoryId;//商品分类id
    private Long groupId;//规格参数所属的组id
    private String name;                       //参数名
    private Boolean numeric;//是否是数字类型参数
    private String unit;//数字类型参数的单位
    private Boolean generic;//是否是sku通用属性
    private Boolean searching;//是否用于搜索过滤
    private String segments;//数值类型参数
    private String options;//参数的可选值，不允许用户自己填值
    /**
     * 规格参数值
     */
    private Object value;

    public SpecParamDTO(BaseEntity entity) {
        super(entity);
    }

    public static <T extends BaseEntity> List<SpecParamDTO> convertEntityList(Collection<T> list) {
        if (list == null) return Collections.emptyList();
        return list.stream().map(SpecParamDTO::new).collect(Collectors.toList());
    }
}